import request from '@/utils/request'

export function getChartInfo(params:any){
    return new Promise((resolve, reject) => {
        request({
            url: '/tansci/xxl-job-admin/chartInfo',
            method: 'post',
            data: params
        }).then((res:any) => {
            resolve(res.data)
        }).catch((e:any) => {
            reject(e)
        })
    })
}

export function groupDetail(id){
  return new Promise((resolve, reject) => {
    request({
      url: '/tansci/xxl-job-admin/jobgroup/loadById',
      method: 'post',
      data: 'id='+id
    }).then((res:any) => {
        resolve(res.data)
    }).catch((e:any) => {
        reject(e)
    })
  })
}

export function getGroupList(params:any){
  return new Promise((resolve, reject) => {
    return request({
      url: '/tansci/xxl-job-admin/jobgroup/pageList',
      method: 'post',
      data: params
    }).then((res:any) => {
        resolve(res.data)
    }).catch((e:any) => {
        reject(e)
    })
  })
}

export function create(params) {
  return new Promise((resolve, reject) => {
    return request({
      url: '/tansci/xxl-job-admin/jobgroup/save',
      method: 'post',
      data: params
    }).then((res:any) => {
        resolve(res.data)
    }).catch((e:any) => {
        reject(e)
    })
  })
}

export function remove(id) {
  return new Promise((resolve, reject) => {
    return request({
      url: '/tansci/xxl-job-admin/jobgroup/remove',
      method: 'get',
      params: {id: id}
    }).then((res:any) => {
        resolve(res.data)
    }).catch((e:any) => {
        reject(e)
    })
  })
}

export function update(params) {
  return new Promise((resolve, reject) => {
    return request({
      url: '/tansci/xxl-job-admin/jobgroup/update',
      method: 'post',
      data: params
    }).then((res:any) => {
        resolve(res.data)
    }).catch((e:any) => {
        reject(e)
    })
  })
}


export function jobEnums() {
  return new Promise((resolve, reject) => {
    return request({
     url: '/tansci/xxl-job-admin/jobinfo/enums',
      method: 'get'
    }).then((res:any) => {
        resolve(res.data)
    }).catch((e:any) => {
        reject(e)
    })
  })
}

export function getJobPageList(params) {
  return new Promise((resolve, reject) => {
    return request({
      url: '/tansci/xxl-job-admin/jobinfo/pageList',
      method: 'post',
      data: params
    }).then((res:any) => {
        resolve(res.data)
    }).catch((e:any) => {
        reject(e)
    })
  })
}

export function getJobsByGroup(groupId) {
  return new Promise((resolve, reject) => {
    return request({
      url: '/tansci/xxl-job-admin/jobinfo/jobsByGroup',
      method: 'get',
      params: {groupId: groupId}
    }).then((res:any) => {
        resolve(res.data)
    }).catch((e:any) => {
        reject(e)
    })
  })
}

export function createJob(params) {
  return new Promise((resolve, reject) => {
    return request({
      url: '/tansci/xxl-job-admin/jobinfo/add',
      method: 'post',
      data: params
    }).then((res:any) => {
        resolve(res.data)
    }).catch((e:any) => {
        reject(e)
    })
  })
}

export function removeJob(id) {
  return new Promise((resolve, reject) => {
    return request({
      url: '/tansci/xxl-job-admin/jobinfo/remove',
      method: 'get',
      params: {id: id}
    }).then((res:any) => {
        resolve(res.data)
    }).catch((e:any) => {
        reject(e)
    })
  })
}

export function updateJob(params) {
  return new Promise((resolve, reject) => {
    return request({
      url: '/tansci/xxl-job-admin/jobinfo/update',
      method: 'post',
      data: params
    }).then((res:any) => {
        resolve(res.data)
    }).catch((e:any) => {
        reject(e)
    })
  })
}
//执行一次触发
export function jobTrigger(param) {
  return new Promise((resolve, reject) => {
    return request({
      url: '/tansci/xxl-job-admin/jobinfo/trigger',
      method: 'post',
      data: param
    }).then((res:any) => {
        resolve(res.data)
    }).catch((e:any) => {
        reject(e)
    })
  })
}

export function nextTriggerTimeJob(scheduleType,scheduleConf) {
  return new Promise((resolve, reject) => {
    return request({
      url: '/tansci/xxl-job-admin/jobinfo/nextTriggerTime',
      method: 'post',
      data: 'scheduleType='+scheduleType+'&scheduleConf='+scheduleConf
    }).then((res:any) => {
        resolve(res.data)
    }).catch((e:any) => {
        reject(e)
    })
  })
}

export function jobStart(id) {
  return new Promise((resolve, reject) => {
    return request({
      url: '/tansci/xxl-job-admin/jobinfo/start',
      method: 'post',
      data: 'id='+id
    }).then((res:any) => {
        resolve(res.data)
    }).catch((e:any) => {
        reject(e)
    })
  })
}

export function jobStop(id) {
  return new Promise((resolve, reject) => {
    return request({
      url: '/tansci/xxl-job-admin/jobinfo/stop',
      method: 'post',
      data: 'id='+id
    }).then((res:any) => {
        resolve(res.data)
    }).catch((e:any) => {
        reject(e)
    })
  })
}

export function getJobsByGroupLogs(groupId) {
  return new Promise((resolve, reject) => {
    return request({
      url: '/tansci/xxl-job-admin/joblog/getJobsByGroup',
      method: 'post',
      data: 'jobGroup='+groupId
    }).then((res:any) => {
        resolve(res.data)
    }).catch((e:any) => {
        reject(e)
    })
  })
}

export function getLogsList(params) {
  return new Promise((resolve, reject) => {
    return request({
      url: '/tansci/xxl-job-admin/joblog/pageList',
      method: 'post',
      params: params
    }).then((res:any) => {
        resolve(res.data)
    }).catch((e:any) => {
        reject(e)
    })
  })
}

export function stopJob(id) {
  return new Promise((resolve, reject) => {
    return request({
      url: '/tansci/xxl-job-admin/joblog/logKill',
      method: 'get',
      params: {id: id}
    }).then((res:any) => {
        resolve(res.data)
    }).catch((e:any) => {
        reject(e)
    })
  })
}

export function getJobDetail(params) {
  return new Promise((resolve, reject) => {
    return request({
      url: '/tansci/xxl-job-admin/joblog/logDetailCat',
      method: 'post',
      params: params
    }).then((res:any) => {
        resolve(res.data)
    }).catch((e:any) => {
        reject(e)
    })
  })
}

export function clearLogs(params) {
  return new Promise((resolve, reject) => {
    return request({
      url: '/tansci/xxl-job-admin/joblog/clearLog',
      method: 'get',
      params: params
    }).then((res:any) => {
        resolve(res.data)
    }).catch((e:any) => {
        reject(e)
    })
  })
}
